package cn.wsalix.tld;

import java.io.IOException;

import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;

public class LineFieldTld extends TagSupport {
	private String content = null;
	private int length = 20;

	private static final long serialVersionUID = 1L;

	public LineFieldTld() {

	}

	public int doStartTag() throws JspTagException {
		return Tag.EVAL_BODY_INCLUDE;
	}

	public int doEndTag() throws JspTagException {
		JspWriter out = pageContext.getOut();
		try {
			if (content.length() < length) {
				out.println(content);
			} else {
				out.println("<a title=\"" + content + "\">"
						+ content.substring(0, length) + "...</a>");
				// out.println(content.substring(0, length)+"...");
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return Tag.SKIP_BODY;
	}

	public void release() {
		super.release();
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public int getLength() {
		return length;
	}

	public void setLength(int length) {
		this.length = length;
	}

}
